package vk.message.gui.component;

import vk.message.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

public class BottomTabButton extends FrameLayout {
    private int notificationsCount = 0;

    private final TextView countTextView;
    private final ImageView countImageView;

    private final TextView nameTextView;
    private final ImageView pictureImageView;


    public BottomTabButton(Context context) {
        this(context, null);
    }

    public BottomTabButton(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BottomTabButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.tab_button_bottom, this);
        countTextView = (TextView) findViewById(R.id.text_tab_notify_count);
        nameTextView = (TextView) findViewById(R.id.text_tab_name);
        countImageView = (ImageView) findViewById(R.id.image_tab_notify);
        pictureImageView = (ImageView) findViewById(R.id.image_tab);
    }

    public int getNotificationsCount() {
        return notificationsCount;
    }

    public ImageView getPictureImageView() {
        return pictureImageView;
    }

    public TextView getNameTextView() {
        return nameTextView;
    }

    public void setNotificationsCount(int notificationsCount) {
        this.notificationsCount = notificationsCount;
        if (notificationsCount > 0) {
            countImageView.setVisibility(INVISIBLE);
            countTextView.setVisibility(INVISIBLE);
        } else {
            countImageView.setVisibility(VISIBLE);
            countTextView.setVisibility(VISIBLE);
            countTextView.setText(String.valueOf(notificationsCount));
        }
    }
}
